package com.hdrx.fundhelper.controller;

import com.hdrx.fundhelper.common.R;
import com.hdrx.fundhelper.dao.pojo.Userinfo;
import com.hdrx.fundhelper.inter.RedisCache;
import com.hdrx.fundhelper.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author: houdx
 * @description:
 * @date: 2023/6/19 14:07
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/queryUserById")
    @ApiOperation("根据id用户信息")
    @ApiImplicitParam(value = "id", name = "id", required = true, paramType = "query")
   // @RedisCache
    public R queryUserById(Integer id){
        R r = new R();
        r.setCode(200);
        r.setBody(userService.queryUserById(id));
        return r;
    }

    @PostMapping("/addUser")
    @ApiOperation("新增用户信息")
    public R addUser(@RequestBody @Valid Userinfo userinfo) {
        userService.addUser(userinfo);
        return R.ok();
    }

    @GetMapping("/queryUser")
    @ApiOperation("查询用户信息")
    @ApiImplicitParam(value = "id", name = "id", required = true, paramType = "query")
    public R queryUser(Integer id) {
        Userinfo userinfo = userService.queryUser(id);
        R r = new R();
        r.setBody(userinfo);
        r.setCode(200);
        r.setMessage("ok");
        return r;
    }
    @GetMapping("/deleById")
    @ApiOperation("逻辑删除用户信息")
    @ApiImplicitParam(value = "id", name = "id", required = true, paramType = "query")
    public R deleById(Integer id){
        if (userService.deleteById(id)>0){
            return R.ok();
        }
            return R.error();
    }
}
